<%#
name: Job - Invocation Report
snippet: false
template_inputs:
- name: job_id
  required: true
  input_type: user
  description: Id of job invocation to report
  advanced: false
  value_type: plain
  resource_type: JobInvocation
  hidden_value: false
- name: hosts
  required: false
  input_type: user
  description: Field for filter hosts of job invocation. Leave blank for all hosts.
  advanced: false
  value_type: search
  resource_type: Host
  hidden_value: false
model: ReportTemplate
require:
- plugin: foreman_remote_execution
￼ version: 4.4.0
-%>
<%- report_headers 'Host', 'stdout', 'stderr', 'debug', 'Result', 'Finished' -%>
<%- invocation = find_job_invocation_by_id(input('job_id')) -%>
<%- parts = ["job_invocation.id = #{input('job_id')}"] -%>
<%- parts << input('hosts') unless input('hosts').blank? -%>
<%- search = parts.map { |part| '(' + part + ')' }.join(' AND ') -%>
<%- load_hosts(search: search).each do |batch| -%>
<%-   batch.each do |host|  -%>
<%-     task = invocation.sub_task_for_host(host) -%>
<%-     outputs = { 'stdout' => [], 'stderr' => [], 'debug' => [] }  -%>
<%-     task.action_continuous_output.each do |output| -%>
<%-       outputs[output['output_type']] << output['output'] -%>
<%-     end -%>
<%-     report_row(
            'Host': host.name,
            'stdout': join_with_line_break(outputs['stdout']),
            'stderr': join_with_line_break(outputs['stderr']),
            'debug': join_with_line_break(outputs['debug']),
            'Result': task.result,
            'Finished': task.ended_at.blank? ? nil : format_time(task.ended_at),
        ) -%>
<%-   end -%>
<%- end -%>
<%= report_render -%>
